//
//  WelcomePage.m
//  我的片刻
//
//  Created by dllo on 15/10/21.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "WelcomePage.h"
#import "FitHeader.h"
#import <UIKit/UIKit.h>
@implementation WelcomePage

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageArray = [NSArray arrayWithObjects:@"yindao1", @"3756672", @"yindao3", nil];
        self.scrollView = [[UIScrollView alloc] init];
        _scrollView.pagingEnabled = YES;
        _scrollView.delegate = self;
        _scrollView.showsHorizontalScrollIndicator = NO;
        [self addSubview:_scrollView];
        }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _scrollView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    _scrollView.contentSize = CGSizeMake(self.frame.size.width * _imageArray.count, self.frame.size.height);
    _scrollView.contentOffset = CGPointMake(0, 0);
    for (NSInteger i = 0; i < _imageArray.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height)];
        imageView.image = [UIImage imageNamed:_imageArray[i]];
        [_scrollView addSubview:imageView];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_scrollView.contentOffset.x > self.frame.size.width * (_imageArray.count - 1) + 50) {
        [UIView animateWithDuration:2 animations:^{
            self.alpha = 0;
        }];
        [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(removeGuideView) userInfo:nil repeats:NO];
    }
}

- (void)removeGuideView
{
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
